package dn.easy.common.utils.bottompopmenu;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import butterknife.ButterKnife;
import dn.easy.common.R;
import dn.easy.common.bean.CommonEntity;

/**
 * Class name
 * Created by  2018/5/23 0023 13:18.
 * Author by yangjing
 */
public class ViewAdatper extends BaseAdapter {

    private List<CommonEntity> lists;
    private Context contexts;

    TextView mTvName;
    ImageView mImageView;

    public ViewAdatper(Context context, List<CommonEntity> lists) {
        this.contexts = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return lists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        CommonEntity entity = lists.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(contexts).inflate(R.layout.item_view_title, null);
            mTvName = (TextView)convertView.findViewById(R.id.tv_name);
            mImageView = (ImageView)convertView.findViewById(R.id.iv_title);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (entity != null) {
            mTvName.setText(entity.getTitle());
            mImageView.setBackgroundResource(entity.getHeadimg());
        }
        return convertView;
    }

    static class ViewHolder {
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}